package com.yhsoft.bill.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhsoft.bill.controller.request.SalerSkInVo;
import com.yhsoft.bill.controller.request.SalerYszkInVo;
import com.yhsoft.bill.controller.request.SalerYszkMxInVo;
import com.yhsoft.bill.controller.response.SalerYszkMxOutVo;
import com.yhsoft.bill.controller.response.SalerYszkOutVo;
import com.yhsoft.bill.service.ISalerYszkMxService;
import com.yhsoft.bill.service.ISalerYszkService;
import com.yhsoft.common.response.PageResult;
import com.yhsoft.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 渠道商应收账款 前端控制器
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-11-03
 */
@Api(tags = {"H-财务统计-渠道商应收账款"})
@RestController
@RequestMapping("/bill/salerYs")
public class SalerYszkController {
    @Resource
    private ISalerYszkService iSalerYszkService;

    @Resource
    private ISalerYszkMxService iSalerYszkMxService;

    @ApiOperation("应收账款列表")
    @GetMapping("/getYszkList")
    public Result<PageResult<SalerYszkOutVo>> getYszkList(SalerYszkInVo inVo,
                                                          @RequestParam(value = "pageNo") Long pageNo,
                                                          @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SalerYszkOutVo> iPage = iSalerYszkService.getYszkList(inVo, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("应收账款详情")
    @GetMapping("/getYszkMx")
    public Result<PageResult<SalerYszkMxOutVo>> getYszkMx(SalerYszkMxInVo inVo,
                                                          @RequestParam(value = "customerId") Integer customerId,
                                                          @RequestParam(value = "pageNo") Long pageNo,
                                                          @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SalerYszkMxOutVo> iPage = iSalerYszkMxService.getYszkMx(inVo, customerId, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("收款")
    @PostMapping("/sk")
    public Result<?> sk(@RequestBody SalerSkInVo inVo) {
        String result = iSalerYszkMxService.sk(inVo);
        if(result.equals("success")){
            iSalerYszkService.sk(inVo);
            return Result.success(result);
        }
        return Result.fail(result);
    }
}
